import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/components/commons/Home'
import Dashboard from '@/components/pages/Dashboard'
import BaseTable from '@/components/pages/BaseTable'
import Tabs from '@/components/pages/Tabs'
import BaseForm from '@/components/pages/BaseForm'
import Editor from '@/components/pages/Editor'
import Markdown from '@/components/pages/Markdown'
Vue.use(Router)

const router = new Router({
  routes: [{
    path: '/home',
    redirect: '/dashboard'
  }, {
    path: '/home',
    name: 'home',
    component: Home,
    meta: {
      title: '首页'
    },
    children: [{
      path: '/dashboard',
      name: 'dashboard',
      component: Dashboard,
      meta: {
        title: '系统首页'
      }
    }, {
      path: '/table',
      name: 'table',
      component: BaseTable,
      meta: {
        title: '基础表格'
      }
    }, {
      path: '/tabs',
      name: 'tabs',
      component: Tabs,
      meta: {
        title: 'tab选项卡'
      }
    }, {
      path: '/form',
      name: 'form',
      component: BaseForm,
      meta: {
        title: '基本表单'
      }
    }, {
      path: '/editor',
      name: 'editor',
      component: Editor,
      meta: {
        title: '富文本编辑器'
      }
    }, {
      path: '/markdown',
      name: 'markdown',
      component: Markdown,
      meta: {
        title: 'markdown编辑器',
        routeList: [{
          name: '首页',
          lujing: '/'
        }, {
          name: '第二页面',
          lujing: '/aa/bb'
        }, {
          name: '第三页面',
          lujing: '/aa/bb/cc'
        }]
      }
    }]
  }]
})
router.beforeEach((to, from, next) => {
  console.log(to)
  let routeList = []
  to.matched.forEach(element => {
    routeList.push({
      name: element.meta.title,
      lujing: element.path
    })
  })
  to.meta.routeList = routeList
  next()
})
export default router
